using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using DbDiff.DbDiff_Common;
using DbDiff.DbDiffWinClient.BusinessObjects;


namespace DbDiff.DbDiffWinClient.Forms
{
	public class ucSpDiffInfo : DbDiff.DbDiffWinClient.Forms.ucItemInfoBase
	{
		private DiffControl.DiffView diffView;
		private Databases _databases;
		private System.ComponentModel.IContainer components = null;

		public ucSpDiffInfo(DataRow itemInfoRow, DbDiff.DbDiffWinClient.BusinessObjects.Databases databases, bool windowButton)
			: base (itemInfoRow, windowButton)
		{
			// This call is required by the Windows Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitializeComponent call
			_isButtons = false;
			DiffViewInit (databases);
		}

		private void DiffViewInit(DbDiff.DbDiffWinClient.BusinessObjects.Databases databases) 
		{
			string sp1Text = string.Empty;
			string sp2Text = string.Empty;
			_databases = databases;
			DataRow[] selectedRows;

			diffView.Init(string.Empty, string.Empty);

			//sp1
			selectedRows = databases.Database1.DatabaseObject.dbObj.dtObjects.Tables[dbObjectsTable.tblDetails.ToString()].Select("ObjectOwner='" + _owner + "' and Name='" + _name + "'");
			//selectedRows = databases.Database1.DatabaseObject.dbObj.dtObjects.Tables[dbObjectsTable.tblDetails.ToString()].Select("Name='" + _name + "'");
			if ((selectedRows != null) &&
				(selectedRows.Length > 0))
			{
				if ((selectedRows[0]["Text"] != null) &&
					(selectedRows[0]["Text"] != DBNull.Value)) 
				{
					sp1Text = selectedRows[0]["Text"].ToString();
				}
			}
			
			//sp2
			selectedRows = databases.Database2.DatabaseObject.dbObj.dtObjects.Tables[dbObjectsTable.tblDetails.ToString()].Select("ObjectOwner='" + _owner + "' and Name='" + _name + "'");
			//selectedRows = databases.Database2.DatabaseObject.dbObj.dtObjects.Tables[dbObjectsTable.tblDetails.ToString()].Select("Name='" + _name + "'");
			if ((selectedRows != null) &&
				(selectedRows.Length > 0))
			{
				if ((selectedRows[0]["Text"] != null) &&
					(selectedRows[0]["Text"] != DBNull.Value)) 
				{
					sp2Text = selectedRows[0]["Text"].ToString();
				}
			}
			
			diffView.Init(sp1Text, sp2Text);
		}


		public void Init(DataRow itemInfoRow, DbDiff.DbDiffWinClient.BusinessObjects.Databases databases) 
		{
			DiffViewInit (databases);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.diffView = new DiffControl.DiffView();
			this.panelMain.SuspendLayout();
			this.panelButton.SuspendLayout();
			this.SuspendLayout();
			// 
			// txtOwner
			// 
			this.txtOwner.BackColor = System.Drawing.SystemColors.Window;
			this.txtOwner.Name = "txtOwner";
			// 
			// lblOwner
			// 
			this.lblOwner.Name = "lblOwner";
			// 
			// txtName
			// 
			this.txtName.BackColor = System.Drawing.SystemColors.Window;
			this.txtName.Name = "txtName";
			// 
			// lblName
			// 
			this.lblName.Name = "lblName";
			// 
			// panelMain
			// 
			this.panelMain.Controls.Add(this.diffView);
			this.panelMain.Name = "panelMain";
			this.panelMain.Controls.SetChildIndex(this.diffView, 0);
			this.panelMain.Controls.SetChildIndex(this.lblName, 0);
			this.panelMain.Controls.SetChildIndex(this.txtName, 0);
			this.panelMain.Controls.SetChildIndex(this.lblOwner, 0);
			this.panelMain.Controls.SetChildIndex(this.txtOwner, 0);
			// 
			// panelButton
			// 
			this.panelButton.Name = "panelButton";
			// 
			// btnOk
			// 
			this.btnOk.Name = "btnOk";
			// 
			// btnCancel
			// 
			this.btnCancel.Name = "btnCancel";
			// 
			// btnModify
			// 
			this.btnModify.Name = "btnModify";
			// 
			// btnDelete
			// 
			this.btnDelete.Name = "btnDelete";
			// 
			// btnNew
			// 
			this.btnNew.Name = "btnNew";
			// 
			// btnClose
			// 
			this.btnClose.Name = "btnClose";
			// 
			// diffView
			// 
			this.diffView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.diffView.Location = new System.Drawing.Point(8, 64);
			this.diffView.Name = "diffView";
			this.diffView.Size = new System.Drawing.Size(472, 216);
			this.diffView.TabIndex = 10;
			// 
			// ucSpDiffInfo
			// 
			this.Name = "ucSpDiffInfo";
			this.panelMain.ResumeLayout(false);
			this.panelButton.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		protected override void ShowForm()
		{
			ucSpDiffInfo spDiffInfo = new ucSpDiffInfo(_itemInfoRow, _databases, false);
			frmItemInfoForm itemInfoform = new frmItemInfoForm(spDiffInfo);
			itemInfoform.Show();
		}

	}
}


